<?php 

class Buyback_ShippingLabelController extends Zend_Controller_Action{
	
	protected $orderId;
	public function preDispatch(){
		if($this->getRequest()){
			$this->orderId = $this->_getParam('orderId');
		}
	}
	
	public function indexAction(){
		if(null == $this->orderId){
			$this->view->message = "No Order was Selected";
			return false;
		}
		
		$filename = md5($this->orderId) . ".pdf";
		
		if(file_exists(APPLICATION_PATH . '/shippinglabel/' . $filename)){
			$pdf = Zend_Pdf::load($filename);
		}
		
//		create a new PDF file
		$pdf = new Zend_Pdf();
		
		                 //Add new page
                 $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER);
                 $pdf->pages[] = $page;

                 //Add content to page
                 $pageWidth = $page->getWidth();
                 $pageHeight = $page->getHeight();
                 $LeftAlignMeasure = $pageWidth;
                 $TopAlignMeasure = $pageHeight;
                 
                 $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES), 8);
                 
                 $page->drawText("ISBN", 20, $pageHeight -= 15);
                 $page->drawText("Title", 100, $pageHeight);
                 $page->drawText("Offer", 500, $pageHeight);
                 $page->drawText("Qty", 530, $pageHeight);
                  $page->drawText("SubTotal", 550, $pageHeight);
                  $page->drawLine(10, $pageHeight - 2, $pageWidth - 10, $pageHeight - 2 );
		
		
//		save a new PDF file
		$pdf->save(APPLICATION_PATH . '/shippinglabel/' . $filename);
		
		$this->view->filename = $filename;		
	}
}